home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dbase / lib19.zip / FRPG.PRG < prev    next >
Text File  |  1992-09-28  |  17KB  |  419 lines

  1. *-------------------------------------------------------------------------------
  2. *-- Program...: FRPG.PRG
  3. *-- Programmer: Ken Mayer (KENMAYER)
  4. *-- Date......: 09/28/1992
  5. *-- Notes.....: These are Fantasy Role-Playing Game routines. For examples of 
  6. *--             the use of these routines, in much detail, I have a gaming
  7. *--             system (constantly being modified) that uses these routines 
  8. *--             extensively. It's a fantasy system, based in 'Middle Earth'. 
  9. *--             It includes: Character Generation (updating, printing, deleting);
  10. *--             Random Encounters (Wilderness and City); and Random Treasure 
  11. *--             Generation. If interested, contact me. Information is in 
  12. *--             README.TXT. This system is not yet ready for 'public
  13. *--             consumption', but sometime early 1992 ... (RSN  <G>)
  14. *-------------------------------------------------------------------------------
  15.  
  16. PROCEDURE SetRand
  17. *-------------------------------------------------------------------------------
  18. *-- Programmer..: Ken Mayer (KENMAYER)
  19. *-- Date........: 02/18/1992
  20. *-- Notes.......: A small procedure used to set a random number table. Used with
  21. *--               DICE(), etc. below, it can be quite handy. NOTE: You should
  22. *--               use EITHER this routine, OR  RAND(-1) (built in to dBASE).
  23. *-- Written for.: dBASE IV, 1.1
  24. *-- Rev. History: None
  25. *-- Calls.......: None
  26. *-- Called by...: Any
  27. *-- Usage.......: Do SetRand
  28. *-- Example.....: Do SetRand
  29. *-- Returns.....: None
  30. *-- Parameters..: None
  31. *-------------------------------------------------------------------------------
  32.  
  33.     private x,nSeed
  34.     nSeed = (val(substr(time(),1,2)) + val(substr(time(),4,2))+;
  35.                val(substr(time(),7,2))) * val(substr(time(),7,2))
  36.     x=int(rand(nSeed) * 6) + 1
  37.  
  38. RETURN
  39. *-- EoP: SetRand
  40.  
  41. FUNCTION Dice
  42. *-------------------------------------------------------------------------------
  43. *-- Programmer..: Ken Mayer (KENMAYER)
  44. *-- Date........: 02/13/1992
  45. *-- Notes.......: A small function used to determine a random number from
  46. *--               1 to x. Used for gaming purposes.
  47. *-- Written for.: dBASE IV, 1.1
  48. *-- Rev. History: 05/23/1991 - original function.
  49. *--               02/13/1992 -- Ken Mayer -- discovered after playing with this
  50. *--                that there are some problems with resetting the random table
  51. *--                each time. This has been removed. It also means that a 
  52. *--                couple of routines that used to be based on this can use
  53. *--                it better (see: MULTDICE() below ...)
  54. *-- Calls.......: None
  55. *-- Called by...: Any
  56. *--               MULTDICE()       Function in FRPG.PRG
  57. *-- Usage.......: Dice(<nSides>)
  58. *-- Example.....: nVal = Dice(4)
  59. *-- Returns.....: Random # between 1 and <nSides>
  60. *-- Parameters..: nSides = # of sides of die to be cast ... (RPG dice
  61. *--                        include 4, 6 (standard), 8, 10, 12, 20, 100 ...
  62. *-------------------------------------------------------------------------------
  63.  
  64.     parameters nSides
  65.  
  66.    *-- return a random number from 0 to nSides -1 and add 1 to it ...
  67. RETURN int(rand() * nSides) + 1
  68. *-- EoF: Dice()
  69.  
  70. FUNCTION MultDice
  71. *-------------------------------------------------------------------------------
  72. *-- Programmer..: Ken Mayer (KENMAYER)
  73. *-- Date........: 02/13/1992
  74. *-- Notes.......: Function like above, used to determine a random #,
  75. *--               but for multiple dice, of x# of sides.
  76. *-- Written for.: dBASE IV, 1.1
  77. *-- Rev. History: 06/12/1991 - original function.
  78. *--               02/13/1992 -- cleaned up to call DICE() above for each
  79. *--                iteration, rather than calling once and then redoing the
  80. *--                randomizer logic ... I was setting the random table
  81. *--                in the DICE() function, but decided it was more trouble
  82. *--                than it was worth ... resetting it too fast (i.e., in a loop)
  83. *--                and I was getting the exact same number 2 to 4 times in a
  84. *--                row ... not worth it. SO, I don't anymore.
  85. *-- Calls.......: DICE()               Function in FRPG.PRG
  86. *-- Called by...: Any
  87. *-- Usage.......: MultDice(<nNum>,<nSides>)
  88. *-- Example.....: nVal = MultDice(3,6)
  89. *-- Returns.....: Random value of 1 to x (x being number of sides), 
  90. *--               for each iteration (nNum), totalled. For example,
  91. *--               value returned would be the total of 3 six-sided die
  92. *--               rolled, the number would be anywhere from 3 to 18.
  93. *-- Parameters..: nNum   = Number of dice to be "rolled"
  94. *--               nSides = # of sides to the dice (see Dice() above)
  95. *-------------------------------------------------------------------------------
  96.  
  97.     parameters nNum,nSides
  98.     private nCount,nTotal
  99.     
  100.     nCount = 0                             && set counter
  101.     nTotal = 0                             && set total
  102.     do while nCount < nNum                 && loop for number of dice 
  103.         nCount = nCount + 1                 && increment counter
  104.         nTotal = nTotal + dice(nSides)      && add to total
  105.     enddo
  106.     
  107. RETURN nTotal
  108. *-- EoF: MultDice()
  109.  
  110. FUNCTION ValiDice
  111. *-------------------------------------------------------------------------------
  112. *-- Programmer..: Ken Mayer (KENMAYER)
  113. *-- Date........: 06/08/1992
  114. *-- Notes.......: Used to ask user for input of a number within a range
  115. *--               based on gaming dice. Programmer supplies # of dice,
  116. *--               and number of sides to function, it returns the input
  117. *--               from the user (and only allows valid input).
  118. *-- Written for.: dBASE IV, 1.1
  119. *-- Rev. History: 07/09/1991 - original function.
  120. *--               02/13/1992 -- modified to handle user pressing <Esc>.
  121. *--               06/08/1992 -- explicit color handling
  122. *-- Calls.......: SHADOW               Procedure in PROC.PRG
  123. *--               CENTER               Procedure in PROC.PRG
  124. *-- Called by...: Any
  125. *-- Usage.......: ValiDice(<nNum>,<nDice>,"<cMessage>","<cColor>")
  126. *-- Example.....: replace STRENGTH with ValiDice(3,6,"Strength",;
  127. *--                                       "rg+/gb,w/n,rg+/gb")  && 3 6-sided
  128. *-- Returns.....: Valid user input
  129. *-- Parameters..: nNum     = Number of dice
  130. *--               nSides   = Number of sides
  131. *--               cMessage = Message for line 0
  132. *--               cColor   = Colors for window
  133. *-------------------------------------------------------------------------------
  134.  
  135.     PARAMETERS nNum, nDice, cMessage, cColor
  136.     private nUpper,nUser 
  137.     
  138.     save screen to sDice
  139.     activate screen
  140.     define window wDice from 8,20 to 14,60 double color &cColor
  141.     do shadow with 8,20,14,60
  142.     activate window wDice
  143.     
  144.     nUpper = nNum * nDice    && upper limit
  145.     do center with 0,40,"","&cMessage"
  146.     do center with 1,40,"","Enter a value from "+ltrim(str(nNum))+" to "+;
  147.                             ltrim(str(nUpper))
  148.     do center with 2,40,"","("+ltrim(str(nNum))+"d"+ltrim(str(nDice))+")"
  149.     nUser = 0
  150.     do while .t.
  151.         @4,18 get nUser picture "999" valid required nUser => nNum .and.;
  152.                                                  nUser =< nUpper;
  153.                              error chr(7)+"Enter a valid number!"
  154.         read 
  155.         if lastkey() = 27
  156.             ?? chr(7)
  157.         else
  158.             exit
  159.         endif
  160.     enddo
  161.  
  162.     deactivate window wDice
  163.     release window wDice
  164.     restore screen from sDice
  165.     release screen sDice
  166.     
  167. RETURN nUser
  168. *-- EoF: ValiDice()
  169.  
  170. FUNCTION DiceChoose
  171. *-------------------------------------------------------------------------------
  172. *-- Programmer..: Ken Mayer (KENMAYER)
  173. *-- Date........: 06/08/1992
  174. *-- Notes.......: This is another FRPG routine -- It is used to give the
  175. *--               user a choice of three die roles. The computer will
  176. *--               randomly generate a die roll three times so the user
  177. *--               has a choice. 
  178. *-- Written for.: dBASE IV, 1.1
  179. *-- Rev. History: 07/09/1991 - original function
  180. *--               02/13/1992 -- Modified to only require use of MULTDICE(),
  181. *--               not a call to DICE() AND MULTDICE() ... also modified to
  182. *--               deal with user pressing <Esc> (it beeps at 'em).
  183. *--               06/08